package constant.milk.cashbook.asset;

import constant.milk.cashbook.R;
import constant.milk.cashbook.SuperActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;

public class AddFlagActivity extends SuperActivity
{
	public static final String ADDFLAG_DATA = "ADDFLAG_DATA";
	
	private View addFlagOkView;
	private View addFlagNoView;
	
	private RadioButton addFlagOkRadio;
	private RadioButton addFlagNoRadio;
	
	private Button checkButton;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.addflag_activity);
		
		setGoneTipButton();
		
		setTitle("자산포함유무");
		
		setFindViewId();
		setOnClick();
		setData();
	}

	@Override
	protected void setFindViewId()
	{
		addFlagOkView = findViewById(R.id.addFlagOkView);
		addFlagNoView = findViewById(R.id.addFlagNoView);
		
		addFlagOkRadio = (RadioButton) findViewById(R.id.addFlagOkRadio);
		addFlagNoRadio = (RadioButton) findViewById(R.id.addFlagNoRadio);
		
		checkButton = (Button) findViewById(R.id.checkButton);
	}

	@Override
	protected void setOnClick()
	{
		addFlagOkView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setOkChecked();
			}
		});
		
		addFlagNoView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setNoChecked();
			}
		});
		
		checkButton.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent intent = new Intent();
				
				if (addFlagNoRadio.isChecked())
				{
					intent.putExtra(ADDFLAG_DATA, getResources().getString(R.string.addFlagNo));
				}
				else
				{
					intent.putExtra(ADDFLAG_DATA, getResources().getString(R.string.addFlagOk));
				}
				
				setResult(Activity.RESULT_OK, intent);
				finish();
			}
		});
	}

	@Override
	protected void setData()
	{
		Intent intent = getIntent();
		String flag = intent.getStringExtra(ADDFLAG_DATA);
		
		if (flag.equals(getResources().getString(R.string.addFlagNo)))
		{
			setNoChecked();
		}
		else
		{
			setOkChecked();
		}
	}

	private void setOkChecked()
	{
		addFlagOkRadio.setChecked(true);
		addFlagNoRadio.setChecked(false);
	}
	
	private void setNoChecked()
	{
		addFlagOkRadio.setChecked(false);
		addFlagNoRadio.setChecked(true);
	}
	
	@Override
	protected void tipButton()
	{
	}

}
